|
1
|
|
|
/* global $ */ |
|
2
|
|
|
function process_btn_press(element, state) { |
|
3
|
|
|
var popover = element.parents('.popover'); |
|
4
|
|
|
var taskid = popover.prev().data('taskid'); |
|
5
|
|
|
var data = {id: taskid, state: state}; |
|
6
|
|
|
// send actual HTTP POST request to app |
|
7
|
|
|
$.post('/set_task_state', data) |
|
8
|
|
|
.done(function() { |
|
9
|
|
|
// Reload page after new state was set |
|
10
|
|
|
// TODO reloading the whole page is bad but whatever... |
|
11
|
|
|
location.reload(); |
|
12
|
|
|
}); |
|
13
|
|
|
// TODO error handling? |
|
14
|
|
|
popover.popover('hide'); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
// Init popovers |
|
18
|
|
|
var popovers = $('[data-toggle="popover"]'); |
|
19
|
|
|
popovers.popover({ |
|
20
|
|
|
placement: 'bottom auto', |
|
21
|
|
|
html: true, |
|
22
|
|
|
content: '<div class="btn-group">' + |
|
23
|
|
|
'<button type="button" class="btn btn-warning btn-backlog">Backlog</button>' + |
|
24
|
|
|
'<button type="button" class="btn btn-danger btn-todo">ToDo</button>' + |
|
25
|
|
|
'<button type="button" class="btn btn-success btn-done">Done</button>' + |
|
26
|
|
|
'</div>' |
|
27
|
|
|
}); |
|
28
|
|
|
// Only one popover at a time |
|
29
|
|
|
popovers.click(function(){ |
|
30
|
|
|
popovers.not(this).popover('hide'); |
|
31
|
|
|
}); |
|
32
|
|
|
// Button events |
|
33
|
|
|
$(document).on('click', '.popover .close', function(){ |
|
34
|
|
|
$(this).parents('.popover').popover('hide'); |
|
35
|
|
|
}); |
|
36
|
|
|
$(document).on('click', '.btn-backlog', function(){ |
|
37
|
|
|
process_btn_press($(this), 0); |
|
38
|
|
|
}); |
|
39
|
|
|
$(document).on('click', '.btn-todo', function(){ |
|
40
|
|
|
process_btn_press($(this), 1); |
|
41
|
|
|
}); |
|
42
|
|
|
$(document).on('click', '.btn-done', function(){ |
|
43
|
|
|
process_btn_press($(this), 2); |
|
44
|
|
|
}); |
|
45
|
|
|
|